﻿/*
** Xin YUAN, 2023, BSD (2)
*/

////////////////////////////////////////////////////////////////////////////////

//Task framework

class work_data_base;
class task_base;

class task_util
{
private:
	typedef void (*task_callback)(work_data_base* pw, task_base* pv);  //noexcept

private:
	task_callback callback{NULL};

private:
	friend class task_base;
	template <class U>
	friend class task_impl;
};

#if defined(WIN32)

#include "windows/task_base.h"

#elif defined(__linux__)

#include "linux/task_base.h"

#else

#error This OS system is not supported!

#endif

//task_impl<T>

template <class T>
class task_impl : public task_base
{
private:
	typedef task_impl<T>  thisClass;

protected:
	task_impl() noexcept
	{
	}
	task_impl(const task_impl&) = delete;
	~task_impl() noexcept
	{
	}

	task_impl& operator=(const task_impl&) = delete;

public:
	bool Initialize() noexcept
	{
		return init(&task_cb);
	}

private:
	static void task_cb(work_data_base* pw, task_base* pv) noexcept
	{
		thisClass* pThis = static_cast<thisClass*>(pv);
		T* pT = static_cast<T*>(pThis);
		pT->DoWork(pw);
	}

protected:
//overrideables
	//void DoWork(work_data_base* p) noexcept;
};

////////////////////////////////////////////////////////////////////////////////
